﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="wfAddOrder.aspx.cs" Inherits="msBsc.WebUi.wMall.Buyer.wfAddOrder" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>游客_添加订单</title>
    <link href="/themes/wStyle1/css/sLayout.css" rel="stylesheet" />
    <link href="/themes/wStyle1/css/sHead.css" rel="stylesheet" />
    <link href="/themes/wStyle1/css/sFoot.css" rel="stylesheet" />
    <link href="/themes/wStyle1/css/usermenu.css" rel="stylesheet" />
    <link href="/themes/wStyle1/css/from.css" rel="stylesheet" />
    <link href="/themes/wStyle1/css/pagination.css" rel="stylesheet" />
    <link href="/themes/wStyle1/css/orderlist.css" rel="stylesheet" />
    <link href="/jqPlugin/layer/skin/layer.css" rel="stylesheet" />
    <link href="/jqPlugin/laydate/skins/default/laydate.css" rel="stylesheet" />

    <link href="/themes/wStyle1/css/Chat/layim.css" rel="stylesheet" />
</head>
<body>
    <div class="wf_all">
        <div id="divLoginInfo">
            <%=msBsc.WebUi.Code.QtHtmlGet.GetHeaderLoginInfo() %>
        </div>
        <div class="main-container">
            <div class="sidebar-scroll noborder">
                <%=msBsc.WebUi.Code.QtHtmlGet.GetTouristMenuHtml() %>
            </div>
            <div class="main-Info">
                <div class="tnavigation">
                    <a class="nav" href="#">首页</a>&gt;
				<a class="nav" href="#">订单管理</a>&gt;
				<a class="nav-on" href="#">我的订单</a>
                </div>
                <div id="CarInfo">
                    <p style="width: 200px; margin-left: 30px;" class="car-price">数据加载中请稍后...</p>
                </div>
                <xmp id="svc_list_temp_order" style="display: none">
                    <table class="table-info">
                        <thead class="table-head">
                            <tr>
                                <th class="w2">名称</th>
                                <th class="w2">时间</th>
                                <th>车辆价总价(元)</th>
                            </tr>
                        </thead>
                        <tbody class="user-body">
                            <tr class="tr-one">
                                <td class="w2">
                                    <div class="user-tag">
                                        <div><a href="#">{{d.rows[0].CUSTOMER_NICK}}</a></div>
                                        <span userface="{{d.rows[0].CUSTOMER_DEFAULT_PIC}}" 
                                            username="{{d.rows[0].CUSTOMER_NICK}}" 
                                            userid="{{d.rows[0].DJACK_ID}}" lg="true" 
                                            style="cursor: pointer; color: #ff6a00;"  onclick="chatShow(this);">
                                            <img alt="在线咨询" src="/themes/wStyle1/Images/Chat/contact.gif">
                                        </span>
                                    </div>
                                    <img src="{{d.rows[0].CUSTOMER_NICK}}" alt="用户头像" class="user-img">
                                </td>
                                <td>
                                    <span id="startime" style="padding-right: 26px;" class="laydate-icon" ></span>
                                    --
                                    <span id="endtime" style="padding-right: 26px;" class="laydate-icon" ></span>
                                </td>
                                <td>
                                    <p class="unit-price" id="price_sum">￥{{d.rows[0].VEHICLE_PRICE_DAY}}</p>
                                </td>
                            </tr>
                        </tbody>
                    </table>
                    <table class="table-info m-top1">
                        <thead class="table-head">
                            <tr>
                                <th>车辆</th>
                                <th class="w5"></th>
                                <th>单价(元/天)</th>
                                <th>操作</th>
                            </tr>
                        </thead>
                        <tbody id="subimtCar" class="car-body">
                            <tr carid="{{d.rows[0].VEHICLE_INFO_ID}}">
                                <td><a href="/wp_VehicleInfo.htm?vehicleId={{d.rows[0].PRODUCT_ID}}" target="_blank">
                                    <img src="{{d.rows[0].VEHICLE_DEFAULT_PIC}}" class="car-img"></a>
                                </td>
                                <td class="car-info">
                                    <p>{{d.rows[0].VEHICLE_NAME}}</p>
                                    <p>{{getServerTypeName(d.rows[0].VEHICLE_SERVICE_TYPE)}} /{{d.rows[0].VEHICLE_SEATS}}座</p>
                                </td>
                                <td class="center-text statusx">
                                    <p class="car-price">￥<span>{{d.rows[0].VEHICLE_PRICE_DAY}}</span></p>
                                    <p class="center-text">优惠 -￥<span>0.00</span></p>
                                </td>
                                <td style="text-align:center">
                                    <span style="cursor:pointer" onclick="removeCar(this)">删除</span>
                                </td>
                            </tr>
                        </tbody>
                    </table>
                </xmp>
                <div id="carList" style="display: none;">
                </div>
                <xmp id="car_temp_list" style="display: none">
                    <div style="max-height:530px;overflow-y:auto;overflow-x:hidden;">
                    <table class="table-info m-top1" style="width:843px;">
                        <thead class="table-head">
                            <tr>
                                <th class="w1"><input type="checkbox" isall="0" onclick="checkAll(this);" />全选</th>
                                <th>车辆</th>
                                <th class="w3"></th>
                                <th>单价(元/天)</th>
                            </tr>
                        </thead>
                        <tbody id="allcarList" class="car-body" style="width:835px;">
                            {{#for(var i=0,len=d.rows.length;i < len;i++){ }}
                            <tr carid="{{d.rows[i].VEHICLE_INFO_ID}}">
                                <td style="border-right:1px solid #dee5ea;text-align:center;"><input isall="1" type="checkbox" /></td>
                                <td>
                                    <img src="{{d.rows[i].VEHICLE_DEFAULT_PIC}}" class="car-img" />
                                </td>
                                <td class="car-info">
                                    <p>{{d.rows[i].VEHICLE_NAME}}</p>
                                    <p>{{getServerTypeName(d.rows[i].VEHICLE_SERVICE_TYPE)}} /{{d.rows[i].VEHICLE_SEATS}}座</p>
                                </td>
                                <td class="center-text statusx">
                                    <p class="car-price">￥<span>{{d.rows[i].VEHICLE_PRICE_DAY}}</span></p>
                                    <p class="center-text">优惠 -￥<span>0.00</span></p>
                                </td>
                               
                            </tr>
                             {{#} }}
                        </tbody>
                    </table>
                    <div class="zuihou-submit" style="width:120px;">
                        <span class="up-btn tm-skin-red" id="okCar" onclick="selectCar();">确认添加</span>
                    </div>
                        </div>
                </xmp>

                <div class="zuihou">
                    <div class="zuihou-right" id="Operation">
                        <div class="zuihou-submit">
                            <span class="up-btn tm-skin-yellow" onclick="addCar();">继续添加</span>
                            <span class="up-btn tm-skin-red" onclick="comintCar(this)">提交订单</span>
                        </div>
                        <div class="zuihou-info text-right">
                            <p>订单总价:<span id="price_sum2" class="car-price">￥0.00</span></p>
                            <p>
                                优惠:<span id="price_amt" class="zuihou-price">-￥0.00</span>
                                实付:<span id="shifu" class="zuihou-price">-￥0.00</span>
                            </p>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <%--chat--%>
        <script src="/themes/wStyle1/js/Chat/lib.js"></script>
        <script src="/themes/wStyle1/js/Chat/layim.js"></script>
        <script src="/jqPlugin/laydate/laydate.js"></script>
        <!--start JS引用-->
        <script src="/jqPlugin/js/jquery-1.8.3.min.js"></script>
        <script src="/jqPlugin/js/jBase.js"></script>
        <script src="/jqPlugin/js/jBPage.js"></script>
        <script src="/jqPlugin/js/laytpl.js"></script>
        <script src="/jqPlugin/layer/layer.min.js"></script>


        <script src="/themes/wStyle1/js/comm/VerifyJs.js"></script>
        <script src="/themes/wStyle1/js/comm/DateInfo.js"></script>
        <script src="/themes/wStyle1/js/Chat/chatMessage.js"></script>

        <script src="/jqPlugin/SelectSimu/js/SelectSimu.js"></script>
        <script src="/themes/wStyle1/js/comm/jsLayout.js"></script>
        <script type="text/javascript">
            $(document).ready(function () {
                setTimeout(function () {
                    var startime = {
                        elem: '#startime',
                        format: 'YYYY-MM-DD hh:mm',
                        min: laydate.now(), //设定最小日期为当前日期
                        max: '2099-06-16 23:59:59', //最大日期
                        istime: true,
                        istoday: false,
                        choose: function (datas) {
                            endtime.min = datas; //开始日选好后，重置结束日的最小日期
                            endtime.start = datas //将结束日的初始值设定为开始日
                            var enddate = $("#endtime").html();
                            if (IsNull(enddate)) {
                                return;
                            }
                            priceSum();
                        }
                    };
                    var endtime = {
                        elem: '#endtime',
                        format: 'YYYY-MM-DD hh:mm',
                        min: laydate.now(),
                        max: '2099-06-16 23:59:59',
                        istime: true,
                        istoday: false,
                        choose: function (datas) {
                            startime.max = datas; //结束日选好后，重置开始日的最大日期
                            var stardate = $("#startime").html();
                            if (IsNull(stardate)) {
                                return;
                            }
                            priceSum();
                        }
                    };
                    laydate(startime);
                    laydate(endtime);
                }, 1000);
            });

            //价格计算
            function priceSum() {
                var startTime = $("#startime").html(), stopTime = $("#endtime").html();
                var days = 1;
                //天数 判断
                if (IsNull(startTime) || IsNull(stopTime)) {
                    days = 1
                }
                else {
                    startTime = startTime.replace(/-/g, "/");
                    stopTime = stopTime.replace(/-/g, "/");
                    var sTime = formatDate(new Date(startTime), false);
                    var tTime = formatDate(new Date(stopTime), false);
                    days = parseInt(new Date(tTime).getTime() - new Date(sTime).getTime()) / 1000 / 60 / 60 / 24 + 1;
                    if (days > 1) {
                        var stopTemp = stopTime.split(" ");
                        var arrStopTemp = stopTemp[1].split(":");
                        if (arrStopTemp[0] == "00" && arrStopTemp[1] == "00") {
                            days -= 1;
                        }
                    }
                    else {
                        days = 1;
                    }
                }
                jisuanSum(days);
            }



            //获取车辆信息
            function getOrderInfo() {
                var opart = new jsonRow();
                opart.AddCell("carid", GetQueryStr("carid"));
                opart.AddCell("ACTION", 'init');
                ajaxComm(opart);
            }
            var layerIndex = 0;


            //选择的车辆
            function selectCar() {
                var html = '', istrue = false;
                //是否有选中的
                $("input[type='checkbox']").each(function (i, e) {
                    if ($(e).attr("isall") == "1" && $(e).attr("checked")) {
                        istrue = true;
                        return false;
                    }
                });
                if (!istrue) {
                    layer.alert('必须选择一个商品', 3); return;
                }

                //添加html
                $("input[type='checkbox']").each(function (i, e) {
                    if ($(e).attr("checked") && i > 0) {
                        var tr = $(e).parent().parent();
                        var td = $(tr).children("td");

                        html += '<tr carid="' + $(tr).attr("carid") + '">';
                        html += '<td>' + $(td).eq(1).html() + '</td>';
                        html += '<td class="car-info">' + $(td).eq(2).html() + '</td>';
                        html += '<td class="center-text statusx">' + $(td).eq(3).html() + '';
                        html += '<td style="text-align:center" >';
                        html += '<span style="cursor:pointer" onclick="removeCar(this)">删除</span></td></tr>';
                    }
                });

                $("#subimtCar").children("tr").remove();
                $.layer({
                    shade: [0.5, '#000', true],
                    area: ['auto', 'auto'],
                    dialog: {
                        msg: '你确定添加该产品？',
                        btns: 2,
                        type: 4,
                        btn: ['确认', '取消'],
                        yes: function (e) {
                            $("#subimtCar").append(html);
                            priceSum();
                            layer.close(e);
                            layer.close(layerIndex);

                        }, no: function () {
                        }
                    }
                });

            }

            //计算 总价格
            function jisuanSum(days) {
                var zongjia = 0, youhuijia = 0;

                $("#subimtCar").children("tr").each(function (i, e) {
                    $(e).children("td").each(function (j, k) {
                        if (j == 2) {
                            var prices = $(k).children("p");
                            zongjia += parseFloat($(prices).eq(0).children("span").eq(0).html());
                            youhuijia += parseFloat($(prices).eq(1).children("span").eq(0).html());
                        }
                    });
                });
                $("#shifu").html("￥" + ((zongjia - youhuijia) * days).toFixed(2));

                zongjia = zongjia * days;
                youhuijia = youhuijia * days;
                $("#price_sum").html("￥" + (zongjia).toFixed(2));
                $("#price_sum2").html("￥" + (zongjia).toFixed(2));
                $("#price_amt").html("-￥" + (youhuijia).toFixed(2));


            }
            //删除汽车
            function removeCar(t) {
                if ($("#subimtCar").children("tr").length <= 1) {
                    layer.alert("订单必须有一个商品", 3);
                    return;
                }
                $(t).parent("td").parent("tr").remove();

                priceSum();
            }

            //添加车辆
            function addCar() {
                if ($("#allcarList").children().length > 0) {
                    //已经添加的车辆
                    $("input[type='checkbox']").each(function (i, e) {
                        var tr = $(e).parent().parent();
                        var isadd = false;
                        $("#subimtCar").children("tr").each(function (j, k) {
                            if ($(tr).attr("carid") == $(k).attr("carid")) {
                                $(e).attr("checked", "checked");
                                isadd = true;
                                return false;
                            }
                        });

                        if (!isadd) {
                            $(e).attr("checked", false);
                        }
                    });
                }

                layerIndex = $.layer({
                    type: 1,
                    title: false,
                    fix: false,
                    offset: ['100px', ''],
                    area: ['845px', '550px'],
                    page: { dom: '#carList' }
                });
            }
            //确认提交
            function comintCar(t) {
                //时间验证
                var startime = $("#startime").html();
                var endtime = $("#endtime").html();
                var tNum = 1;
                if (IsNull(startime)) {
                    layer.tips('请选择开始时间', $("#startime"), { guide: 0, time: 2 });
                    return;
                }
                else if (IsNull(endtime)) {
                    layer.tips('请选择结束时间', $("#endtime"), { guide: 0, time: 2 });
                    return;
                }

                if (!isStartEndDate(startime, endtime)) {
                    layer.tips('开始日期必须大于结束日期', $("#endtime"), { guide: 0, time: 2 });
                    return;
                }
                //获取添加的车辆
                var carids = "";
                if ($("#subimtCar").children("tr").length < 1) {
                    layer.tips('请先添加一个车辆', $(t), { guide: 0, time: 2 });
                    return;
                }

                $("#subimtCar").children("tr").each(function (i, e) {
                    carids += $(e).attr("carid") + "|";
                });
                //提交数据
                $.layer({
                    shade: [0.5, '#000', true],
                    area: ['auto', 'auto'],
                    dialog: {
                        msg: '你确定提交该订单？',
                        btns: 2,
                        type: 4,
                        btn: ['确认', '取消'],
                        yes: function (e) {
                            layer.load('正在处理,请稍后', 2);
                            var opart = new jsonRow();
                            opart.AddCell("startime", startime);
                            opart.AddCell("endtime", endtime);
                            opart.AddCell("carids", carids);
                            opart.AddCell("ACTION", "comintCar");
                            ajaxComm(opart);
                            layer.close(e);
                        }, no: function () {

                        }
                    }
                });

            }
            //时间判断
            function isStartEndDate(startDate, endDate) {
                if (startDate.length > 0 && endDate.length > 0) {
                    var startDateTemp = startDate.split(" ");
                    var endDateTemp = endDate.split(" ");
                    var arrStartDate = startDateTemp[0].split("-");
                    var arrEndDate = endDateTemp[0].split("-");
                    var arrStartTime = startDateTemp[1].split(":");
                    var arrEndTime = endDateTemp[1].split(":");
                    var allStartDate = new Date(arrStartDate[0], arrStartDate[1], arrStartDate[2], arrStartTime[0], arrStartTime[1]);
                    var allEndDate = new Date(arrEndDate[0], arrEndDate[1], arrEndDate[2], arrEndTime[0], arrEndTime[1]);
                    if (allStartDate.getTime() >= allEndDate.getTime()) {
                        return false;
                    }
                }
                return true;
            }
            //全选效果
            function checkAll(t) {
                if ($(t).attr("checked")) {
                    $("input[type='checkbox']").attr("checked", 'true');
                }
                else {
                    $("input[type='checkbox']").removeAttr("checked");
                }
            }

            //服务类型获取
            function getServerTypeName(type) {
                var tp = parseInt(type);
                switch (type) {
                    case 1:
                        return "司机兼导游";
                        break;
                    case 2:
                        return "司机兼向导";
                        break;
                    case 3:
                        return "专职司机和专业导游";
                        break;
                    default:
                        return "其他";
                        break;
                }
            }

            //成功效果
            function success(orderid) {
                layer.alert('操作成功', 1);
                setTimeout(function () {
                    location.href = "/wb_OrderInfo.htm?orderId=" + orderid;
                }, 2000);
            }

            getOrderInfo();
        </script>

        <%=msBsc.WebUi.Code.QtHtmlGet.GetFloorHtml() %>
    </div>
</body>
</html>
